package form

import (
	"yak.admin/src/entity"
	"yak.admin/src/util"
)

type LoginForm struct {
	Username string `form:"username"`
	Password string `form:"password"`
}

func (form *LoginForm) Login() (entity.Admin, bool)  {
	db := util.GetMysqlPool().Handler()
	admin := entity.Admin{}
	db.Where("username = ? AND password = ?", form.Username, admin.GetPassword(form.Password)).First(&admin)
	if admin.Id > 0 {
		return admin, true
	}
	return admin, false
}
